package com.exhibition.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.exhibition.service.ITbExhInfoService;
import com.exhibition.service.ITbExhUnitService;
import com.exhibition.service.ITbInviteService;
import com.exhibition.service.ITbVenueService;
import com.exhibition.util.Util;

@Controller
public class TbExhInfoController {
	
	@Autowired
	ITbExhInfoService tbExhInfoService;
	@Autowired
	ITbInviteService tbInviteService;
	@Autowired
	ITbExhUnitService tbExhUnitService;
	@Autowired
	ITbVenueService tbVenueService;
	
	@RequestMapping("admin/exhinfoList.do")	
	public ModelAndView list(HttpServletRequest request,String ehi_name){
		ModelAndView mav=new ModelAndView("./exhinfo/list.jsp");
		Map<String,Object> map=new HashMap<String,Object>();
		map.put("ehi_name", ehi_name);
		mav.addObject("list", tbExhInfoService.getList(map));
		mav.addObject("ehi_name", ehi_name);
		return mav;
	}
	@RequestMapping("admin/exhinfoDetail.do")	
	public ModelAndView update(HttpServletRequest request,String ehi_id){
		ModelAndView mav=new ModelAndView("./exhinfo/detail.jsp");
		Map<String,Object> map=new HashMap<String,Object>();
		map.put("ehi_id", ehi_id);
		mav.addObject("exhinfo", tbExhInfoService.getOne(map));
		return mav;
	}
	@RequestMapping("admin/exhinfoDelete.do")	
	public ModelAndView delete(HttpServletRequest request,String ehi_id){
		ModelAndView mav=new ModelAndView("redirect:/admin/exhinfoList.do");
		tbExhInfoService.delete(ehi_id);
		return mav;
	}
	@RequestMapping("host/exhinfoAdd.do")	
	public ModelAndView add(HttpServletRequest request){
		ModelAndView mav=new ModelAndView("./exhinfo/add.jsp");
		Map<String,Object> map=new HashMap<String,Object>();
		mav.addObject("list", tbVenueService.getList(map));
		return mav;
	}
	@RequestMapping("host/exhiAddOk.do")	
	public ModelAndView addOk(HttpServletRequest request,
			  String ehi_name,
			  String ven_id,
			  String ehi_file_no,
			  String ehi_start_time,
			  String ehi_end_time,
			  String ehi_fix_time,
			  String ehi_address,
			  String ehi_host_unit,
			  String ehi_und_unit,
			  String ehi_spo_no,
			  String ehi_in_fee,
			  String ehi_out_fee,
			  String ehi_qua
				  ){
		ModelAndView mav=new ModelAndView("./exhinfo/add.jsp");
		Map<String,Object> map=new HashMap<String,Object>();
		  map.put("ehi_id",Util.getPrimaryKey());
		  map.put("host_id",request.getSession().getAttribute("host_id"));
		  map.put("ehi_name",ehi_name);
		  map.put("ven_id",ven_id);
		  map.put("ehi_file_no",ehi_file_no);
		  map.put("ehi_start_time",ehi_start_time);
		  map.put("ehi_end_time",ehi_end_time);
		  map.put("ehi_fix_time",ehi_fix_time);
		  map.put("ehi_address",ehi_address);
		  map.put("ehi_host_unit",ehi_host_unit);
		  map.put("ehi_und_unit",ehi_und_unit);
		  map.put("ehi_spo_no",ehi_spo_no);
		  map.put("ehi_in_fee",ehi_in_fee);
		  map.put("ehi_out_fee",ehi_out_fee);
		  map.put("ehi_qua",ehi_qua);
		  map.put("ehi_state","1");
		  tbExhInfoService.add(map);
		return mav;
	}
	@RequestMapping("host/exhinfoList.do")	
	public ModelAndView exhinfoList(HttpServletRequest request,String ehi_name){
		ModelAndView mav=new ModelAndView("./exhinfo/list.jsp");
		Map<String,Object> map=new HashMap<String,Object>();
		map.put("host_id", request.getSession().getAttribute("host_id"));
		map.put("ehi_name", ehi_name);
		List<Map<String,Object>> list=tbExhInfoService.getList(map);
		for (int i = 0; i < list.size(); i++) {
			Map<String,Object> heMap=new HashMap<String,Object>();
			heMap.put("exh_id", list.get(i).get("ehi_id"));
			list.get(i).put("invate_count", tbInviteService.getList(heMap).size());
			list.get(i).put("join_count", tbExhUnitService.getList(heMap).size());
		}
		mav.addObject("list", list);
		mav.addObject("ehi_name", ehi_name);
		return mav;
	}
	@RequestMapping("host/exhinfoUpdate.do")	
	public ModelAndView exhinfoUpdate(HttpServletRequest request,String ehi_id){
		ModelAndView mav=new ModelAndView("./exhinfo/update.jsp");
		Map<String,Object> map=new HashMap<String,Object>();
		map.put("ehi_id", ehi_id);
		mav.addObject("exhinfo", tbExhInfoService.getOne(map));
		return mav;
	}
	@RequestMapping("host/exhiUpdateOk.do")	
	public ModelAndView exhiUpdateOk(HttpServletRequest request,
			  String ehi_id,
			  String ehi_name,
			  String ehi_file_no,
			  String ehi_start_time,
			  String ehi_end_time,
			  String ehi_fix_time,
			  String ehi_address,
			  String ehi_host_unit,
			  String ehi_und_unit,
			  String ehi_spo_no,
			  String ehi_in_fee,
			  String ehi_out_fee,
			  String ehi_qua
				  ){
		ModelAndView mav=new ModelAndView("redirect:/host/exhinfoList.do");
		Map<String,Object> map=new HashMap<String,Object>();
		  map.put("ehi_id",ehi_id);
		  map.put("ehi_name",ehi_name);
		  map.put("ehi_file_no",ehi_file_no);
		  map.put("ehi_start_time",ehi_start_time);
		  map.put("ehi_end_time",ehi_end_time);
		  map.put("ehi_fix_time",ehi_fix_time);
		  map.put("ehi_address",ehi_address);
		  map.put("ehi_host_unit",ehi_host_unit);
		  map.put("ehi_und_unit",ehi_und_unit);
		  map.put("ehi_spo_no",ehi_spo_no);
		  map.put("ehi_in_fee",ehi_in_fee);
		  map.put("ehi_out_fee",ehi_out_fee);
		  map.put("ehi_qua",ehi_qua);
		  map.put("ehi_state","1");
		  tbExhInfoService.update(map);
		return mav;
	}
	@RequestMapping("host/exhinfoDelete.do")	
	public ModelAndView exhinfoDelete(HttpServletRequest request,String ehi_id){
		ModelAndView mav=new ModelAndView("redirect:/host/exhinfoList.do");
		tbExhInfoService.delete(ehi_id);
		return mav;
	}
	@RequestMapping("host/exhinfoCertain.do")	
	public ModelAndView exhinfoCertain(HttpServletRequest request,String ehi_id){
		ModelAndView mav=new ModelAndView("redirect:/host/exhinfoList.do");
		Map<String,Object> map=new HashMap<String,Object>();
		map.put("ehi_id",ehi_id);
		map.put("ehi_state","2");
		tbExhInfoService.update(map);
		return mav;
	}
	@RequestMapping("host/exhinfoDetail.do")	
	public ModelAndView exhinfoDetail(HttpServletRequest request,String ehi_id){
		ModelAndView mav=new ModelAndView("./exhinfo/detail.jsp");
		Map<String,Object> map=new HashMap<String,Object>();
		map.put("ehi_id", ehi_id);
		mav.addObject("exhinfo", tbExhInfoService.getOne(map));
		return mav;
	}
	@RequestMapping("host/exhinfoStart.do")	
	public ModelAndView exhinfoStart(HttpServletRequest request,String ehi_id){
		ModelAndView mav=new ModelAndView("redirect:/host/exhinfoList.do");
		Map<String,Object> map=new HashMap<String,Object>();
		map.put("ehi_id",ehi_id);
		map.put("ehi_state","3");
		tbExhInfoService.update(map);
		return mav;
	}
}
